<?php
namespace Home\Controller;

use Home\Util\lib\YZTokenClient;
use Util\AccessController;

/*
 * 有赞接口
 */

class DataUpdateController extends AccessController {

    public function YDUpdate() {
        $conn = mssql_conn();
        $sql = "select  dwbh , dwmch,dzhdh  from  mchk where beactive='是' and isxs='是' and shjjg='' or  shjjg is null";
        $sql = iconv('utf-8', 'GB2312//IGNORE', $sql);
        $res = sqlsrv_query($conn, $sql);
        $alldata = array();
        while($row = sqlsrv_fetch_array($res)){
            $data = array();
            $data['ERP_CODE'] = $row['dwbh'];
            $data['NAME'] = iconv('GB2312//IGNORE','utf-8', $row['dwmch']);
            $data['DZ'] =  iconv('GB2312//IGNORE','utf-8', $row['dzhdh']);
            $alldata[] = $data;
        }
        $LS = Service('DataUpdate','kx_all_yd_code');
        $OK = $LS->AddAll($alldata);
        if($OK){
            $this->success('更新成功');
        }else{
            $this->error('更新失败');
        }

    }

    public function GoodsUpdate() {
        $conn = mssql_conn();
        $sql = "select spbh,spmch,zjm,pizhwh,shpchd,shpgg,dw,jlgg from spkfk where beactive='是' and substring(spbh,1,1) not in ('M','B','E','Z','0') AND jixing not in ('注射剂','针剂','注射液')";
        $sql = iconv('utf-8', 'GB2312//IGNORE', $sql);
        $res = sqlsrv_query($conn, $sql);
        $alldata = array();
        while($row = sqlsrv_fetch_array($res)){
            $data = array();
            $data['ERP_CODE'] = $row['spbh'];
            $data['NAME'] = iconv('GB2312//IGNORE','utf-8', $row['spmch']);
            $data['DW'] = iconv('GB2312//IGNORE','utf-8', $row['dw']);
            $data['CJ'] = iconv('GB2312//IGNORE','utf-8', $row['shpchd']);
            $data['GG'] = iconv('GB2312//IGNORE','utf-8', $row['shpgg']);
            $data['PFH'] =  iconv('GB2312//IGNORE','utf-8', $row['pizhwh']);
            $alldata[] = $data;
        }
        $LS = Service('DataUpdate','kx_all_goods_code');
        $OK = $LS->AddAll($alldata);
        if($OK){
            $this->success('更新成功');
        }else{
            $this->error('更新失败');
        }

    }


}